package com.zhengx.fragmentutil;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * name：com.zhengx.fragmentutil
 * class: fragment容器
 * author: zhengx
 * create_time: 19-8-15
 */
public class FragContainer extends Fragment implements IFragmentBackHandler{

    private FragController controller;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        controller = new FragController(getChildFragmentManager());
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        FrameLayout frameLayout = new FrameLayout(inflater.getContext());
        frameLayout.setId(getId());
        controller.setContainerId(getId());
        return frameLayout;
    }

    public FragController getController() {
        return controller;
    }

    @Override
    public boolean onBackPressed() {
        return FragmentUtil.handleFragmentsBackPressed(this);
    }
}
